
const pageConfig = ( {
  /**
   * 
   */
  data: {
    subCategoryData: null
  },

  /**
   * 当一级分类被点击
   * 
   * @param e event
   */
  onMainCategoryTap: function(e) {
    let categoryId = e.currentTarget.dataset.categoryId;
    let categoryData = this.data.categoryData;

    categoryData.forEach((cat, index) => {
      if (categoryId == cat.id) {
        cat.selected = true;
      } else {
        cat.selected = false;
      }
    });

    this.setData({
      categoryData
    });

    api.getCategoryData({
      data: {
        parentId: categoryId
      },
      success: (res) => {
        this.setData({
            subCategoryData: res.data.data
        })
      }
    })
  },

  /**
   * 
   */
  onLoad: function () {
    this.fetchCategoryData();


    api.getCategoryData({
      data: {
        parentId: 1
      },
      success: (res) => {
        this.setData({
          subCategoryData: res.data.data
        })
      }
    })
  }
});


Page(pageConfig);